package cn.leaf.feign.config;

import cn.leaf.feign.endpoint.FeignClientEndpoint;
import feign.Feign;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.LeafFeignClientsRegistrar;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 *
 * description:  Feign配置类
 *
 * @author twinkle leaf
 * @version v1.0.0
 * @since 2021-11-06 17:35:13
 * slogan: There are no two identical leaves in the world.
 *
 */
@Configuration
@ConditionalOnClass(Feign.class)
@Import(LeafFeignClientsRegistrar.class)
@AutoConfigureAfter(EnableFeignClients.class)
public class LeafFeignAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnAvailableEndpoint
    public FeignClientEndpoint feignClientEndpoint(ApplicationContext context) {
        return new FeignClientEndpoint(context);
    }
}
